package login.dao;

import java.sql.SQLException;
import java.util.ResourceBundle;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;


public class MyDataSource {

	public static DataSource setupDataSource() {
		
		
		ResourceBundle rb =  ResourceBundle.getBundle("db");
		
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(rb.getString("dbdriver"));
        ds.setUsername(rb.getString("dbuser"));
        ds.setPassword(rb.getString("dbpassword"));
        ds.setUrl(rb.getString("dburl"));
        return ds;
    }

    public static void printDataSourceStats(DataSource ds) throws SQLException {
        BasicDataSource bds = (BasicDataSource) ds;
        System.out.println("NumActive: " + bds.getNumActive());
        System.out.println("NumIdle: " + bds.getNumIdle());
    }

    public static void shutdownDataSource(DataSource ds) throws SQLException {
        BasicDataSource bds = (BasicDataSource) ds;
        bds.close();
    }
   
}
